home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / OCCUPIED.ASM < prev    next >
Assembly Source File  |  1990-06-23  |  3KB  |  101 lines

  1. ; Subroutine to check if an address range is available for allocation
  2. ; as shared memory.
  3. ; Input:  bx = segment start address
  4. ;      di = # of bytes / 16
  5. ; Returns with carry set if range is occupied
  6. ; All registers saved and restored
  7. ;
  8.     public    occupied_chk
  9. occupied_chk:
  10.     push    ax            ; save registers
  11.     push    bx
  12.     push    cx
  13.     push    dx
  14.     push    si
  15.     push    di
  16.     push    ds
  17. ;
  18. ; first check if there is any ROM in our range
  19. ;
  20.     add    di,bx            ; end of range to check
  21.     mov    dx,0c000h-(2048 shr 4)    ; start of possible ROM area
  22. occ_next2k:
  23.     add    dx,2048 shr 4        ; next 2k segment
  24. occ_nextROM:
  25.     cmp    dx,di            ; ROM addr above our range?
  26.     jae    occ_chk_RAM        ; -yes, go check for RAM
  27.     mov    ds,dx            ; -no, check for ROM
  28.     xor    si,si
  29.     mov    cx,0aa55h        ; ROM signature
  30.     mov    ax,[si]
  31.     cmp    ax,cx            ; any signature?
  32.     jne    occ_next2k
  33.     mov    ch,[si+2]        ; ROM length in 512 byte blocks
  34.     xor    cl,cl
  35.     push    cx
  36.     shl    cx,1            ; # of bytes to checksum
  37.     xor    ah,ah            ; clear accumulated checksum
  38. occ_chksum:
  39.     lodsb                ; get a byte
  40.     add    ah,al            ; add modulo 100h
  41.     loop    occ_chksum        ; repeat for all bytes
  42.     pop    cx
  43.     or    ah,ah            ; is checksum zero?
  44.     jnz    occ_next2k        ; -no, check next 2k addr 
  45.     shr    cx,1            ; -yes, valid ROM found
  46.     shr    cx,1
  47.     shr    cx,1
  48.     add    dx,cx            ; end of ROM
  49.     cmp    dx,bx            ; does it reach into our area?
  50.     ja    occ_is_ROM
  51.     jmp    occ_nextROM
  52. ;
  53. ; no ROM found in our range, check for RAM
  54. ;
  55. occ_chk_RAM:
  56.     mov    ds,bx            ; point segment at start of range
  57.     sub    di,bx            ; compute # of bytes
  58.     mov    cl,4
  59.     shl    di,cl
  60.     xor    bx,bx            ; clear word pointer
  61.     mov    ax,0a5a5h        ; test pattern
  62.     mov    si,05a5ah        ;   and its complement
  63. occ_nextword:
  64.     pushf
  65.     cli                ; disable interrupts
  66.     mov    cx,[bx]         ; save original contents
  67.     mov    dx,[bx+2]        ; save original contents
  68.     mov    [bx],si         ; put our pattern
  69.     mov    [bx+2],ax        ; drain any capacitive memory
  70.     cmp    [bx],si         ; is our pattern still there?
  71.     mov    [bx],cx         ; restore original contents
  72.     mov    [bx+2],dx        ; restore original contents
  73.     jne    occ_no_RAM
  74.     mov    [bx],ax         ; put the complement pattern
  75.     mov    [bx+2],si        ; drain capacitive memory
  76.     cmp    [bx],ax         ; our pattern still there?
  77.     mov    [bx],cx         ; restore original contents
  78.     mov    [bx+2],dx        ; restore original contents
  79.     je    occ_is_RAM        ; -yes, range is occupied
  80. occ_no_RAM:
  81.     popf                ; enable interrupt
  82.     add    bx,2            ; check next word
  83.     cmp    bx,di            ; at end of range?
  84.     jb    occ_nextword
  85.     clc                ; clear carry - range is available
  86.     jmp    short occ_return
  87. occ_is_RAM:
  88.     popf                ; enable interrupts
  89. occ_is_ROM:
  90.     stc                ; set carry - range is occupied
  91. occ_return:
  92.     pop    ds            ; restore registers
  93.     pop    di
  94.     pop    si
  95.     pop    dx
  96.     pop    cx
  97.     pop    bx
  98.     pop    ax
  99.     ret
  100.  
  101.